package com.lin.demo.one2many.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.lin.demo.one2many.po.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository(value = "one2manyUserMapper")
@DS("one2many")
public interface UserMapper {
    @Select("select * from user")
    @Results(
            @Result(property = "dept", column = "deptid", id = true,
            one = @One(select = "com.lin.demo.one2many.mapper.DeptMapper.getDeptById"))
    )
    List<User> getAllUser();

    @Select("select * from user where userid=#{userid}")
    @Results({
            @Result(id = true, column = "deptid", property = "DeptId"),
            @Result(property = "dept", column = "deptid",
                    one = @One(select = "com.lin.demo.one2many.mapper.DeptMapper.getDeptById"))
        }
    )
    User getUserById(Integer userid);

    @Select("select * from user where deptid=#{deptid}")
    List<User> getUserListByDeptId(Integer deptid);
}
